<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box {
            width: 400px;
            height: 400px;
            background-color: red;
        }
    </style>
</head>
<body>

    <div class="box"></div>

<script>
    let box = document.querySelector(".box")
    box.addEventListener("mouseenter", function() {
        alert("鼠标经过")
    })

    box.addEventListener("mouseleave", function() {
        alert("鼠标离开")
    })
</script>
</body>
</html>